package com.wxmblog.photo.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.wxmblog.base.common.utils.PageResult;
import com.wxmblog.base.common.utils.TokenUtils;
import com.wxmblog.photo.common.rest.request.user.ContactInfoRequest;
import com.wxmblog.photo.common.rest.response.user.ContactInfoResponse;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wxmblog.photo.dao.ContactInfoDao;
import com.wxmblog.photo.entity.ContactInfoEntity;
import com.wxmblog.photo.service.ContactInfoService;
import org.springframework.transaction.annotation.Transactional;


@Service("contactInfoService")
public class ContactInfoServiceImpl extends ServiceImpl<ContactInfoDao, ContactInfoEntity> implements ContactInfoService {

    @Transactional
    @Override
    public void addInfo(ContactInfoRequest request) {

        ContactInfoEntity contactInfoEntity = new ContactInfoEntity();
        BeanUtils.copyProperties(request, contactInfoEntity);
        contactInfoEntity.setUserId(TokenUtils.getOwnerId());
        this.save(contactInfoEntity);
    }

    @Override
    public PageResult<ContactInfoResponse> page(Integer pageIndex, Integer pageSize) {
        Page<ContactInfoResponse> page = PageHelper.startPage(pageIndex, pageSize);
        this.baseMapper.page();
        PageResult<ContactInfoResponse> result = new PageResult<>(page);
        return result;
    }
}
